package com.aly.game.exe2lua.objs;

import com.aly.game.exe2lua.enums.ExportConfig;
import com.aly.game.exe2lua.tasks.Mergable;

import java.util.HashMap;
import java.util.Map;

/**
 * aly @ 16-11-12.
 * 数据导出对象
 */
public class ExportContender implements Mergable<ExportContender> {
    private Map<ExportConfig, StringBuilder> export = new HashMap<>();


    public void export(ExportConfig type, StringBuilder sb) {
        StringBuilder builder = export.get(type);
        if (null == builder) {
            export.put(type, builder = new StringBuilder());
        }
        builder.append(sb);
    }

    public StringBuilder export(ExportConfig config) {
        StringBuilder builder = export.get(config);
        if (null == builder) {
            export.put(config, builder = new StringBuilder());
        }
        return builder;

    }

    public void merge(ExportContender join) {
        join.export.forEach((type, stringBuilder) -> export(type).append(stringBuilder));
    }
}
